home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / hotlist_source / source / hotlist_modinit.c next >
C/C++ Source or Header  |  1996-10-15  |  4KB  |  161 lines

  1. /****************************************************************************
  2.  
  3.  hotlist_modinit.c,
  4.  based on "modinit.c - standard initialisation for Opus 5 modules"
  5.  
  6.  this is the same as modinit.c except it also sets up a semaphore.
  7.  
  8.  ****************************************************************************/
  9.  
  10. #define _DOPUS_MODULE_DEF
  11. #include <dopus/modules.h>
  12.  
  13. #ifndef CLIB_EXEC_PROTOS_H
  14. #include <clib/exec_protos.h>
  15. #include <pragmas/exec_pragmas.h>
  16. #endif
  17.  
  18. #ifndef EXEC_MEMORY_H
  19. #include <exec/memory.h>
  20. #endif
  21.  
  22. #ifndef CLIB_LOCALE_PROTOS_H
  23. #include <clib/locale_protos.h>
  24. #include <pragmas/locale_pragmas.h>
  25. #endif
  26.  
  27. // SAS/C stuff
  28. int __saveds __UserLibInit(void);
  29. void __saveds __UserLibCleanup(void);
  30.  
  31. // The libraries we open
  32. struct Library *DOSBase;
  33. struct Library *DOpusBase;
  34. struct Library *IntuitionBase;
  35. struct Library *GfxBase;
  36. struct Library *IconBase;
  37. struct Library *LocaleBase;
  38. struct Library *UtilityBase;
  39. struct Library *LayersBase;
  40. struct Library *WorkbenchBase;
  41. struct Library *GadToolsBase;
  42. struct Library *AslBase;
  43. struct Library *DiskfontBase;
  44. struct Library *TimerBase;
  45. struct Library *RexxSysBase;
  46.  
  47. // Locale pointer
  48. struct DOpusLocale *locale;
  49.  
  50. // Semaphore pointer
  51. struct SignalSemaphore *configsemaphore;
  52.  
  53. // Library initialisation code
  54. __saveds __UserLibInit()
  55. {
  56.     // Initialise pointers
  57.     DOpusBase=0;
  58.     IntuitionBase=0;
  59.     GfxBase=0;
  60.     IconBase=0;
  61.     LocaleBase=0;
  62.     UtilityBase=0;
  63.     LayersBase=0;
  64.     WorkbenchBase=0;
  65.     GadToolsBase=0;
  66.     DiskfontBase=0;
  67.     AslBase=0;
  68.     RexxSysBase=0;
  69.     locale=0;
  70.  
  71.     // Get DOS library (can't really fail)
  72.     DOSBase=OpenLibrary("dos.library",0);
  73.  
  74.     // Open other libraries we need
  75.     if (!(DOpusBase=OpenLibrary("dopus5.library",55)) ||
  76.         !(IntuitionBase=OpenLibrary("intuition.library",37)) ||
  77.         !(GfxBase=OpenLibrary("graphics.library",37)) ||
  78.         !(IconBase=OpenLibrary("icon.library",37)) ||
  79.         !(LayersBase=OpenLibrary("layers.library",37)) ||
  80.         !(GadToolsBase=OpenLibrary("gadtools.library",37)) ||
  81.         !(AslBase=OpenLibrary("asl.library",37)) ||
  82.         !(DiskfontBase=OpenLibrary("diskfont.library",37)) ||
  83.         !(TimerBase=GetTimerBase()) ||
  84.         !(UtilityBase=OpenLibrary("utility.library",37))) return 1;
  85.  
  86.     // Libraries we don't need but want
  87.     WorkbenchBase=OpenLibrary("workbench.library",0);
  88.     RexxSysBase=OpenLibrary("rexxsyslib.library",0);
  89.  
  90.     // Allocate and initialize signal semaphore
  91.     if (!(configsemaphore=AllocVec(sizeof(struct SignalSemaphore),MEMF_CLEAR)))
  92.         return 1;
  93.     InitSemaphore(configsemaphore);
  94.  
  95.     // Allocate and open locale data
  96.     if (!(locale=AllocVec(sizeof(struct DOpusLocale),MEMF_CLEAR)))
  97.         return 1;
  98.     init_locale_data(locale);
  99.  
  100.     // Open locale library
  101.     if (LocaleBase=OpenLibrary("locale.library",38))
  102.     {
  103.         // Initialise catalog
  104.         locale->li_LocaleBase=LocaleBase;
  105.         if (module_info.locale_name)
  106.             locale->li_Catalog=OpenCatalogA(NULL,module_info.locale_name,0);
  107.         locale->li_Locale=OpenLocale(0);
  108.     }
  109.  
  110.     // Succeeded
  111.     return 0;
  112. }
  113.  
  114.  
  115. // Clean up
  116. void __saveds __UserLibCleanup()
  117. {
  118.     // Free locale stuff
  119.     if (locale)
  120.     {
  121.         if (LocaleBase)
  122.         {
  123.             CloseLocale(locale->li_Locale);
  124.             CloseCatalog(locale->li_Catalog);
  125.             CloseLibrary(LocaleBase);
  126.         }
  127.         FreeVec(locale);
  128.     }
  129.  
  130.     // Free semaphore memory -- it should not be possible for it to be in use.
  131.     if (configsemaphore)
  132.         FreeVec(configsemaphore);
  133.  
  134.     // Close libraries
  135.     CloseLibrary(DOpusBase);
  136.     CloseLibrary(IntuitionBase);
  137.     CloseLibrary(GfxBase);
  138.     CloseLibrary(IconBase);
  139.     CloseLibrary(LayersBase);
  140.     CloseLibrary(UtilityBase);
  141.     CloseLibrary(WorkbenchBase);
  142.     CloseLibrary(DiskfontBase);
  143.     CloseLibrary(RexxSysBase);
  144.     CloseLibrary(AslBase);
  145.     CloseLibrary(DOSBase);
  146. }
  147.  
  148.  
  149. // This routine is called by Opus to find out what the module does
  150. ModuleInfo *__asm __saveds L_Module_Identify(register __d0 int num)
  151. {
  152.     // Return module information
  153.     if (num==-1) return &module_info;
  154.  
  155.     // Valid function number?
  156.     if (num>module_info.function_count || !(module_info.function[num].desc)) return 0;
  157.  
  158.     // Return function description
  159.     return (ModuleInfo *)DOpusGetString(locale,module_info.function[num].desc);
  160. }
  161.